<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 关键字搜索 -->
			<cl-search-key placeholder="搜索物品" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert">
			<template #slot-remark="{ scope, isDisabled }">
				<cl-editor-wang
					:height="400"
					v-model="scope.remark"
					mode="simple"
					:disabled="isDisabled"
				/>
			</template>
		</cl-upsert>
	</cl-crud>
</template>

<script lang="ts" name="user-list" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { reactive } from "vue";

const { service } = useCool();

// cl-table
const Table = useTable({
	columns: [
		{
			label: "id",
			prop: "id",
			width: 100
		},
		{
			label: "物品名称",
			prop: "name"
		},

		{
			label: "创建时间",
			prop: "createTime",
			sortable: "desc"
		},
		{
			label: "操作",
			type: "op",
			width: 400,
			buttons: ["edit", "delete", "info"]
		}
	]
});

// cl-upsert
const Upsert = useUpsert({
	dialog: {
		width: "800px"
	},
	items: [
		{
			prop: "name",
			label: "物品名称",
			component: { name: "el-input" },
			required: true
		},
		{
			prop: "remark",
			label: "备注",
			component: {
				name: "slot-remark"
			}
		}
	]
});
console.log(service.user);
// cl-crud
const Crud = useCrud(
	{
		service: service.user.goods
	},
	(app) => {
		app.refresh();
	}
);
</script>
